package com.example.play.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.common.entity.CommendEntity
import com.example.common.entity.MovieVideoEntity
import com.example.image.glide.GlideImgLoader
import com.example.play.adapter.MovieVideoListAdapter.ItemClickListener
import com.example.play.databinding.ItemVideoCommentLayoutBinding
import com.example.play.databinding.ItemVideoPlayLayoutBinding

class CommentListAdapter constructor(private val list:List<CommendEntity>): RecyclerView.Adapter<CommentListAdapter.ItemVideoHolder>() {
    inner class ItemVideoHolder(val dataBinding: ItemVideoCommentLayoutBinding): RecyclerView.ViewHolder(dataBinding.root)
    private var itemClickListener: ItemClickListener?= null
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemVideoHolder {
        return ItemVideoHolder(ItemVideoCommentLayoutBinding.inflate(LayoutInflater.from(parent.context),parent,false))
    }
    interface ItemClickListener{
        fun onItemChildClick(v: View, position: Int, entity: CommendEntity)
    }
    fun setOnItemClickListener(l: ItemClickListener){
        itemClickListener = l
    }
    override fun getItemCount(): Int  = list.size

    override fun onBindViewHolder(holder: ItemVideoHolder, position: Int) {
        val entity=list[position]
        GlideImgLoader.loadCircleImage(holder.dataBinding.root.context,"https://979c-commentimg-1252317822.image.myqcloud.com/e82e0d81a288da0ae16412212da8a208.jpeg",holder.dataBinding.ivUserIcon)
        holder.dataBinding.apply {
            tvUserName.text=entity.nickname
            tvUserDesc.text=entity.content
            tvLikeCount.text=entity.id.toString()
            tvTime.text=entity.createtime
        }
        holder.dataBinding.root.setOnClickListener{
            itemClickListener?.onItemChildClick(it, position, entity)
        }
    }
}